home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / virtmem.exe / VIRTUMEM.DOC < prev    next >
Text File  |  1992-10-08  |  14KB  |  297 lines

  1.                       VirtuMem:  Virtual memory system.
  2.                       ---------------------------------
  3.  
  4. Written by Wayne Knorr for Techsonix Marketing.
  5.  
  6. Suite 630, Atrium II
  7. 840 6th Ave S.W.
  8. Calgary, Alberta
  9. Canada T2P 3E5
  10.  
  11. Phone: (403) 269-6007
  12. Fax:   (403) 265-8484
  13.  
  14. CompuServe ID: 72470,1217
  15.  
  16. These units may be used and distributed freely and without guilt.
  17. To become a registered user, thus receiving the source code  (Turbo
  18. Pascal 6.0) , full documentation with technical overview, updates, and
  19. technical support, send $18.00, to Techsonix Marketing at the
  20. above address, along with the completed registration form found in the file
  21. REGISTER.FRM.
  22.  
  23. VirtuMem is also available for Amiga systems (with C source code).
  24.  
  25. --------------------
  26.  
  27.  
  28. Brief overview:
  29. ---------------
  30.  
  31. VirtuMem is a memory management unit that replaces the traditional heap.
  32. Each allocation, deallocation, and dynamic memory reference is achieved
  33. through a call to one of the VirtuMem procedures or functions.  When there
  34. is no more traditional heap space left, the system (optionally) starts
  35. using expanded memory that is available.  When this is also used up, a
  36. memory image is created on secondary storage automatically.  The parts of
  37. memory that are not commonly used are swapped out of memory, making room for
  38. those that are commonly used.  Typically more than 99.5% of all memory
  39. accesses are found in memory.  Up to 4 Gigabytes of information can
  40. theoretically be handled (for those who found a really good sale on hard
  41. disks.)
  42.  
  43.  
  44. Use:
  45. ----
  46.  
  47. Virtual structures can replace any or all dynamically allocated structures.
  48. These include (but are not limited to) dynamically allocated arrays, records,
  49. and objects.  This conversion is not automatic, so some work must be done
  50. in order to switch existing programs so they may use VirtuMem.  (Turbo Vision
  51. applications are particularly painful since Turbo Vision has its own
  52. memory allocation scheme.)  Every variable that would normally be declared
  53. as a pointer type is now declared as a virtual pointer, which is a longint.
  54. These dynamic structures are accessed through the VirtuMem routines.
  55.  
  56. The three core routines of VirtuMem are called ANew, R, and Depossess.  In
  57. addition to these, three more, OpenBook, CloseBook, and Unstay are needed
  58. to make the system run properly.  The declarations of these, as they appear
  59. in the interface section of the source code, is found in the file
  60. VIRTUMEM.INT.  An example program which uses all of these calls is found
  61. in the file VIRTUEXM.PAS.
  62.  
  63. ANew allocates a new virtual block and returns a virtual pointer (LongInt)
  64. to it.  It takes the size of the structure as a parameter.
  65.  
  66. Depossess frees the space allocated by ANew.  This space may then be used
  67. by subsequent calls to ANew, keeping the size of the virtual memory small.
  68. This takes as parameters the pointer to be freed and the size of the
  69. structure (which should be the same as that passed to ANew).
  70.  
  71. R is used to access a virtumem block.  This is the interface between the
  72. VirtuMem system and the normal memory system.  R takes a virtual pointer
  73. as its parameter and returns a Turbo Pascal pointer to the structure
  74. in real memory.  This pointer to real memory is guaranteed to be valid until
  75. the next call to a VirtuMem routine.  After a call to VirtuMem, however,
  76. there is a chance that the structure may have been kicked out of real memory
  77. to make room for another structure.  The user may have to use type casting
  78. to change the returned value from type Pointer to the individual pointer
  79. type that is required.
  80.  
  81. R takes a second parameter, called Mucky.  Mucky can take one of three values
  82. defined in the VirtuMem unit.  These are called Clen, Dirt, and Stay,  and
  83. give the system an indication of what is going to happen to the data being
  84. accessed.
  85.  
  86. Clen indicates that the structure being accessed is being read only.  After
  87. one read, the fact that the structure is in memory is ignored.  If it later
  88. becomes necessary for that structure to be swapped out to make room in real
  89. memory for a new structure, it is merely overwritten.  The old structure is
  90. not written back to disk since it is assumed that no changes to it were made.
  91. That is, the copy of the structure that is already on disk is assumed to
  92. still be correct.  Typically Clen would be used in a comparison, when
  93. the structure is passed to a procedure as a value parameter, or on the
  94. left hand side of an assignment statement.
  95.  
  96. Dirt indicates that the structure being accessed will in some way be
  97. modified.  When the Virtual Memory access uses the dirt parameter, VirtuMem
  98. ensures that the structure is rewritten to disk before it is swapped out
  99. of real memory.  Typically Dirt would be used on the left hand side of an
  100. assignment statement.
  101.  
  102. Stay is used to force the structure to remain in real memory indefinitely
  103. (until a call is made to the procedure Unstay).  This is necessary in cases
  104. where Turbo Pascal implicitely references a pointer.  Normally, from one
  105. virtual memory call to the next, the virtual pointer remains the same
  106. but the real memory location of a structure may change.  There are, however,
  107. cases where the real memory pointer must also remain the same for some time.
  108. It is in these cases that the Stay parameter is used.  The two most common
  109. cases where this is necessary are in a "With" statement and when passing
  110. a structure in virtual memory by reference.  It is important to keep in
  111. mind that memory taken by a "stayed" virtual memory call is no longer
  112. available to be used by the rest of the system.  The stay parameter should
  113. also be used in single line complex calculations where several calls are
  114. made to VirtuMem and the results are stored internally.
  115.  
  116. Unstay frees a structure that was forced to stay in real memory by using
  117. R with "Stay" as the second parameter.  It takes a virtual pointer as
  118. a parameter which should be the same virtual pointer as was the first
  119. parameter in the call to R.
  120.  
  121. OpenBook initializes the virtual memory system.  It must be called before
  122. any other VirtuMem call.  A boolean flag is required as a parameter.  This
  123. is set to TRUE to suppress the use of EMS, and FALSE to allow the use of
  124. EMS.
  125.  
  126. CloseBook ends the use of EMS, freeing used memory and closing used files.
  127.  
  128.  
  129. Advantages of Using VirtuMem:
  130. -----------------------------
  131.  
  132. VirtuMem allows virtually unlimited dynamic space.  It also gives a seamless
  133. interface to expanded memory.  The VirtuMem system also does a minimal amount
  134. of error checking that may make debugging easier.  For example, it prints
  135. a warning if an attempt is made to reference a structure through a null
  136. pointer.  Also, when pointers are freed they are automatically set back to
  137. null.
  138.  
  139.  
  140. Disadvantages of Using VirtuMem:
  141. --------------------------------
  142.  
  143. Each pointer reference must be surrounded by a call to the routine R.  This
  144. makes programming more cumbersome and also slows down execution time.  All
  145. pointers are of the same type, so compile time type checking is ineffective.
  146.  
  147. Real memory locations of structures can only be found via calls to R or
  148. a complex analysis of the data structures.  Some structures may not even
  149. be in memory, but only on disk.  This makes tracing through dynamic data
  150. structures, such as linked lists, via a debugger very difficult.
  151.  
  152.  
  153. Error Messages:
  154. ---------------
  155.  
  156. VirtuMem may produce several error messages which may be cryptic to the user.
  157. Below is an explanation of what the common ones mean.
  158.  
  159. -Failed mapping.
  160.      A call to the Expanded Memory Manager, attempting to map an expanded
  161. memory page into real memory has failed.  This normally should not happen.
  162.  
  163. -ENTRY.
  164.      The amount of virtual memory being used is greater than the amount that
  165. VirtuMem has been compiled for by default.  Use less or recompile the
  166. VirtuMem unit with the compiler directive VERYLARGE set.
  167.  
  168. -Conventional static memory overflow.  Data will be contorted.
  169. -Conventional stay count is n.
  170. -Static memory overflow.  Data will be contorted.
  171.      These all indicate that there is no real memory left to swap virtual